package com.block.account.factory;

import com.block.account.enums.AccountTypeEnum;
import com.block.account.service.IAccountCommonService;
import com.block.account.service.impl.AccountInfoServiceImpl;
import com.block.account.service.impl.AccountMerchantInfoServiceImpl;
import com.block.common.util.ApplicationContextUtil;

import java.util.HashMap;
import java.util.Map;

public class AccountTypeFactory {

    private static final Map<String, Class<? extends IAccountCommonService>> serviceMap = new HashMap<>();
    static {
        serviceMap.put(AccountTypeEnum.MERCHANT.getValue(), AccountMerchantInfoServiceImpl.class);
        serviceMap.put(AccountTypeEnum.ACCOUNT.getValue(), AccountInfoServiceImpl.class);
    }

    public static IAccountCommonService getService(String accountType){
        if (serviceMap.containsKey(accountType)){
            Class<? extends IAccountCommonService> aClass = serviceMap.get(accountType);
            return ApplicationContextUtil.getBean(aClass);
        }
        return null;
    }

}
